package com.albon.util;

import android.app.KeyguardManager;
import android.content.Context;
import android.os.PowerManager;
import android.util.Log;
//http://www.mtalking.com/?p=391 화면 깨우기 주소 설명 
public class AlarmAlertWakeLock {
	 private static final String TAG = "AlarmAlertWakeLock";
	 private static PowerManager.WakeLock sCpuWakeLock;
//	 private static KeyguardManager km;
//	 private static KeyguardManager.KeyguardLock mKeyguardLock;   
//	 private static boolean isScreenLock;
	 
	 public static void acquireCpuWakeLock(Context context) {
	        Log.v(TAG, "Acquiring cpu wake lock");
//	        if(km == null){
//	        km = (KeyguardManager)context.getSystemService(Context.KEYGUARD_SERVICE);
//	        }
//	        mKeyguardLock = km.newKeyguardLock("keyguad");
	       
	       // Log.d(TAG, "(km.inKeyguardRestrictedInputMode() lock ? : "+km.inKeyguardRestrictedInputMode());
	        if (sCpuWakeLock != null) {
	        	  Log.v(TAG, "sCpuWakeLock != null");
	            return;
	        }

	        PowerManager pm =
	                (PowerManager) context.getSystemService(Context.POWER_SERVICE);

	        sCpuWakeLock = pm.newWakeLock(
	        		PowerManager.FULL_WAKE_LOCK |
	                PowerManager.ACQUIRE_CAUSES_WAKEUP |
	                PowerManager.ON_AFTER_RELEASE, TAG);
	        sCpuWakeLock.acquire();
	        
	        
//	        if (km.inKeyguardRestrictedInputMode()) { //inKeyguardRestrictedInputMode �� ���������� �ƴ����� Ȯ���ϴ� �޼ҵ�
//	        	Log.d(TAG, "lock??");
//	        	mKeyguardLock.disableKeyguard();
//	          isScreenLock = true;
//	        } else {
//	        	Log.d(TAG, "no lock??");
//	          isScreenLock = false;
//	        }
//	        Log.e(TAG, "isScreenLock : "+isScreenLock);
	    }

	   public static void releaseCpuLock() {
	    	 Log.v(TAG, "Releasing cpu wake lock");
//	    	 if (getIsLock()) {
//	    		 Log.e(TAG, "getIsLock : "+getIsLock());
//	    		 if(mKeyguardLock != null){
//	    		  mKeyguardLock.reenableKeyguard();
//	    		  isScreenLock = false;
//	    		 	}
//	    		  } 
	        if (sCpuWakeLock != null) {
	            sCpuWakeLock.release();
	            sCpuWakeLock = null;
	        }
	    }
	    
//	   public static boolean getIsLock(){  //�����¸� true
//	    	return isScreenLock;
//	    }
//	   
//	   public static void setLock(boolean ScreenLock){
//		   isScreenLock =  ScreenLock;
//	   }
}
